<?php 
class CartWS_Model_Address extends Ext_Db_Table
{
	protected $_name = 'sc_address';
	protected $_sequence = 'sc_address_seq';
	protected $_dependentTables = array( 
		'Default_Model_SalesOrderHdr'
	);
	protected $_referenceMap = array(
        'Zone' => array(
            'columns'           => array( 'zone_id' ),
            'refTableClass'     => 'Default_Model_Zone',
            'refColumns'        => array( 'zone_id' )
        )
    );
    
    public function getFromUserId( $userId )
    {
    	$rowset = $this->fetchAll(
    		$this->select()
    		->where('customer_id = ?', $userId )
    		->order('name')
    	);
		if( count( $rowset ) ) {
			return $rowset;
		}  
		return array();
    
    }

    public function getAddressArray( $addressId )
    {   
        $row = $this->find( $addressId )->current();
        if(count( $row )) {
            $address['street_name'] = $row->street_name;
            $address['street_number'] = $row->street_number;
            $address['apt_floor'] = $row->apt_floor;
            return $address;
        }   
        return array();
    
    }   
    
    public function getStringAddress( $addressId )
    {   
        return implode( ' ', $this->getAddressArray( $addressId )); 
    }   
   
    public function getZoneId( $addressId )
    {
        $rowset = $this->fetchAll(
            $this->select()
            ->where('address_id = ?', $addressId )
        );
        if( count( $rowset ) ) {
            return $rowset;
        }
        return array(); 
    }

}
